package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCarStateInfo;
import com.ruoyi.system.service.ISysCarStateInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车况信息Controller
 * 
 * @author ruoyi
 * @date 2022-05-11
 */
@RestController
@RequestMapping("/system/carStateInfo")
public class SysCarStateInfoController extends BaseController
{
    @Autowired
    private ISysCarStateInfoService sysCarStateInfoService;

    /**
     * 查询车况信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysCarStateInfo sysCarStateInfo)
    {
        startPage();
        List<SysCarStateInfo> list = sysCarStateInfoService.selectSysCarStateInfoList(sysCarStateInfo);
        return getDataTable(list);
    }

    /**
     * 导出车况信息列表
     */
    @Log(title = "车况信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCarStateInfo sysCarStateInfo)
    {
        List<SysCarStateInfo> list = sysCarStateInfoService.selectSysCarStateInfoList(sysCarStateInfo);
        ExcelUtil<SysCarStateInfo> util = new ExcelUtil<SysCarStateInfo>(SysCarStateInfo.class);
        util.exportExcel(response, list, "车况信息数据");
    }

    /**
     * 获取车况信息详细信息
     */
    @GetMapping(value = "/{infoId}")
    public AjaxResult getInfo(@PathVariable("infoId") Long infoId)
    {
        return AjaxResult.success(sysCarStateInfoService.selectSysCarStateInfoByInfoId(infoId));
    }

    /**
     * 新增车况信息
     */
    @Log(title = "车况信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCarStateInfo sysCarStateInfo)
    {
        if (sysCarStateInfo == null) return error("空数据!");
        //需要精度正确
        sysCarStateInfo.setCreateAt(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getTime()));
        return toAjax(sysCarStateInfoService.insertSysCarStateInfo(sysCarStateInfo));
    }

    /**
     * 检测车况信息
     */
    @PostMapping("/check")
    public AjaxResult check(@RequestBody SysCarStateInfo sysCarStateInfo)
    {
        if (sysCarStateInfo == null) return error("空数据!");
        return toAjax(sysCarStateInfoService.check(sysCarStateInfo));
    }

    /**
     * 修改车况信息
     */
    @Log(title = "车况信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCarStateInfo sysCarStateInfo)
    {
        return toAjax(sysCarStateInfoService.updateSysCarStateInfo(sysCarStateInfo));
    }

    /**
     * 删除车况信息
     */
    @Log(title = "车况信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{infoIds}")
    public AjaxResult remove(@PathVariable Long[] infoIds)
    {
        return toAjax(sysCarStateInfoService.deleteSysCarStateInfoByInfoIds(infoIds));
    }
}
